{% extends "base.html" %}
{% block title12 %}
    active
{% endblock %}
{% block page-css %}
    <style>
        #hide{
            display: none;
        }
    </style>
{#<link href="/static/multiple-select/css/multi-select.css" rel="stylesheet"/>#}
{#<scritp src=""></scritp>#}
{% endblock %}

{% block page-body %}
    <h1 class="page-header">数据添加</h1>

    <!--面板 开始-->
    <div class="panel panel-primary">
    <div class="panel-heading">软件加固工作量</div>
    <div class="panel-body">

        <div class="panel-body">
            <form class="form-inline" action="/addmyworksoftware/" method="post">
            {% csrf_token %}
                <div class="form-group">
                    <label for="ip">IP</label>
                    <input name="ip" type="text" class="form-control" id="ip" value="10.">
                </div>

                <div class="form-group">
                    <label for="date">加固日期</label>
                    <input name="date" type="date" class="form-control" id="date" value="">
                </div>
                <div class="form-group"><strong>系统版本</strong>
                    <select id="os" name="os" class="form-control">
                        {% for i in os %}
                            <option value="{{ i.id }}">{{ i.os }}</option>
                        {% endfor %}
                    </select>
                </div>
                <div class="form-group "><strong>软件版本</strong>
                    <select id="sw" multiple size="6" name="sw_id" class="form-control">
                        {% for i in sw %}
                            <option class="" id="sw_id{{ i.id }}" value="{{ i.id }}">{{ i.software }}</option>
                            {#                                                        <option>{{ i.software }}</option>#}
                        {% endfor %}
                    </select>
                </div>

                <button type="submit" class="btn btn-success">添加</button>
            </form>
        </div>
        <!--面板 结束-->
    </div>
{% endblock %}

{% block page-script %}



    <script language="JavaScript">
        //自动获取当前日期开始
        // 给input  date设置默认值
        var now = new Date();
        //格式化日，如果小于9，前面补0
        var day = ("0" + now.getDate()).slice(-2);
        //格式化月，如果小于9，前面补0
        var month = ("0" + (now.getMonth() + 1)).slice(-2);
        //拼装完整日期格式
        var today = now.getFullYear() + "-" + (month) + "-" + (day);
        //完成赋值
        $('#date').val(today);
        //自动获取当前日期结束


        $("#os").on('click', function () {
            $("#sw > option").removeClass("hide")
            var sw_obj = $("#sw > option");
            var os_id = $("#os").val();
            console.log(os_id);
            if (os_id >= 5 && os_id <= 12) {
                var rhel5_sw_list = new Array();


                for (i = 0; i < sw_obj.length; i++) {
                    if ($(sw_obj)[i].text.indexOf("el5") ==-1){
                        $((sw_obj)[i]).addClass("hide")
                    }else{
                        rhel5_sw_list.push($(sw_obj[i]).val());
                    }
                }
                $('#sw').val(rhel5_sw_list);
            }

            {#rhel6系统版本软件#}
            if (os_id >= 13 && os_id <= 19) {
                var rhel6_sw_list = new Array();


                for (i = 0; i < sw_obj.length; i++) {
                    if ($(sw_obj)[i].text.indexOf("el6") ==-1){
                        $((sw_obj)[i]).addClass("hide")
                    }else{
                        rhel6_sw_list.push($(sw_obj[i]).val());
                    }
                }
                $('#sw').val(rhel6_sw_list);
            }
            {#rhel7系统版本软件#}
            if (os_id >= 20 && os_id <= 27) {
                var rhel7_sw_list = new Array();
                for (i = 0; i < sw_obj.length; i++) {
                    if ($(sw_obj)[i].text.indexOf("el7") ==-1){
                        $((sw_obj)[i]).addClass("hide")
                    }else{
                        rhel7_sw_list.push($(sw_obj[i]).val());
                    }
                }
                $('#sw').val(rhel7_sw_list);
            }


        })
    </script>

{% endblock %}
